package cn.hust.springboot.service.impl;

import cn.hust.springboot.bean.*;
import cn.hust.springboot.mapper.PositionMapper;
import cn.hust.springboot.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PositionServiceImpl implements IPositionService {
    @Autowired
    private PositionMapper positionMapper;

    @Override
    public List<Position> getAllPositions() {
        PositionExample example = new PositionExample();
        PositionExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return this.positionMapper.selectByExample(example);
    }

    public int addPosition(Position position){
        return positionMapper.insert(position);
    }

    public Position getPositionById(Integer positionId){
        return positionMapper.selectByPrimaryKey(positionId);
    }

    public int updatePosition(Position position){
        return positionMapper.updateByPrimaryKeySelective(position);
    }

    public int deletePositionById(Integer id){
        return positionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Position> query(String posName) {
        PositionExample example = new PositionExample();
        PositionExample.Criteria criteria = example.createCriteria();
        criteria.andNameLike("%"+posName+"%");
        return this.positionMapper.selectByExample(example);
    }
}
